package logic

import (
	"baidu-dev/models"
	"context"
	"errors"

	"baidu-dev/baidurpc/baidurpc"
	"baidu-dev/baidurpc/internal/svc"

	"github.com/zeromicro/go-zero/core/logx"
)

type CollectionAddLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewCollectionAddLogic(ctx context.Context, svcCtx *svc.ServiceContext) *CollectionAddLogic {
	return &CollectionAddLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

// 收藏
func (l *CollectionAddLogic) CollectionAdd(in *baidurpc.CollectionAddRequest) (*baidurpc.CollectionAddResponse, error) {
	// todo: add your logic here and delete this line

	collection := &models.Collection{
		UserId:  int(in.UserId),
		VideoId: int(in.VideoId),
	}

	if err := collection.CollectionAdd(models.DB); err != nil {
		return nil, errors.New("已收藏")
	}

	return &baidurpc.CollectionAddResponse{
		CollectionId: int64(collection.ID),
	}, nil
}
